const db = wx.cloud.database()
const collectionName = 'pointGoods'
export default {
  getList: async function ({
    pageNum,
    pageSize,
    
  }) {
    var skip = (pageNum - 1) * pageSize
    var matchObj = {}
    let res = await db.collection(collectionName).aggregate()
      .match(matchObj)
      .sort({
        createDate: -1
      })
      .skip(skip)

      .limit(pageSize)
      .end()

    return res.list
  },
  get: async function(id){
    let res = await db.collection(collectionName).doc(id).get()
    return res.data
  },
  add: async function (data) {
    data.createDate = new Date()
    return await db.collection(collectionName).add({
      data: data
    })
  },
  
  update: async function (data) {
    let _id = data._id
    delete data._id
    var res = await db.collection(collectionName).doc(_id).update({
      data: data
    })
    return res
  },

  delete: async function (id) {
    var res = await db.collection(collectionName).doc(id).remove()
    return res
  },
}